﻿using System;

namespace _12.PrintIndexesOfLettersOfWordFromArray
{
    class PrintIndexesOfLettersOfWordFromArray
    {
        static void Main()
        {
            char[] alphabet = new char[26];
            int index = 0;
            for (int i = 65; i <= 90; i++)
            {
                alphabet[index] = (char)i;
                index++;
            }
            //for (int i = 0; i < alphabet.Length; i++)
            //{
            //    Console.Write(alphabet[i]+" ");

            //}
            Console.WriteLine("Enter a word with capital leters to see indexes for each leter from the array");
            string word = Console.ReadLine();
            char[] wordArray;
            wordArray = word.ToCharArray();
            //for (int i = 0; i < wordArray.Length; i++)
            //{
            //    Console.Write(wordArray[i] + " ");
            //}
            for (int i = 0; i < wordArray.Length; i++)
            {
                int start = 0;
                int end = alphabet.Length - 1;
                int mid = 0;
                for (int j = 0; j < alphabet.Length; j++)
                {
                    mid = start + (end - start) / 2;
                    if (alphabet[mid] == wordArray[i])
                    {
                        Console.WriteLine("The index of letter {0} in the array is:{1}", wordArray[i], mid);
                        break;
                    }
                    else
                    {
                        if (alphabet[mid] > wordArray[i])
                        {
                            end = mid - 1;
                        }
                        else
                        {
                            start = mid + 1;
                        }
                    }
                }
            }

        }
    }
}
